package kadledav.backend.dao;

import java.util.List;

import javax.persistence.TypedQuery;

import kadledav.backend.model.News;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

@Repository
public class NewsDAO extends GenericDAO<News> {

	Logger logger = Logger.getLogger(NewsDAO.class);

	public NewsDAO() {
		super(News.class);
	}
	
	public List<News> getOrderByDateDesc(int limit) {
		String qlString = "SELECT n FROM News n ORDER BY created DESC";
		logger.debug("executing query: " + qlString);
		TypedQuery<News> query = entityManager.createQuery(qlString, News.class);
		if (limit > 0) {
			query.setMaxResults(limit);
		}
		return query.getResultList();
	}

}
